Include Nur.DateFormat

/// Creator:      fengliang
/// CreatDate:    2021-03-12
/// Description:  巡视记录汇总表
Class Nur.MNISV3.GradeTourRec Extends %Persistent [ ClassType = persistent, Owner = {_SYSTEM}, ProcedureBlock ]
{

/// 巡视日期
Property DHCNurTourDate As %Library.Date(FORMAT = 1) [ InitialExpression = {+$p($h,",",1)}, Required, SqlColumnNumber = 2 ];

/// 巡视时间
Property DHCNurTourTime As %Library.Time [ InitialExpression = {+$p($h,",",2)}, Required, SqlColumnNumber = 3 ];

/// 巡视病人就诊号
Property DHCNurTourAdmDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 4 ];

/// 巡视患者所在病区
Property DHCNurTourCtlocDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 5 ];

/// 巡视病人床号
Property DHCNurTourPatBed As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 6 ];

/// 护理医嘱id
Property DHCNurTourCareDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 7 ];

/// 护理医嘱
Property DHCNurTourCareDesc As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 8 ];

/// 是否离开病房
Property DHCNurTourIfOut As %Library.String(TRUNCATE = 1) [ InitialExpression = "否", SqlColumnNumber = 9 ];

/// 离开原因
Property DHCNurTourIfOutRes As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 10 ];

/// 总体状况
Property DHCNurTourSTAT As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 11 ];

/// 管道情况
Property DHCNurTourTunnelSTAT As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 12 ];

/// 体位
Property DHCNurTourTW As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 13 ];

/// 皮肤情况
Property DHCNurTourSkinSTAT As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 14 ];

/// 巡视人
Property DHCNurTourUser As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 15 ];

/// 作废人
Property DHCNurTourCancelUser As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 16 ];

/// 作废日期
Property DHCNurTourCancelDate As %Library.Date(FORMAT = 1) [ SqlColumnNumber = 17 ];

/// 作废时间
Property DHCNurTourCancelTime As %Library.Time [ SqlColumnNumber = 18 ];

/// 条码类型
Property DHCNurTourBarcodeType As %Library.String [ SqlColumnNumber = 19 ];

/// 对应 item1~15的类型
Property ItemType As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 20 ];

Property Item1 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 21 ];

Property Item2 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 22 ];

Property Item3 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 23 ];

Property Item4 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 24 ];

Property Item5 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 25 ];

Property Item6 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 26 ];

Property Item7 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 27 ];

Property Item8 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 28 ];

Property Item9 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 29 ];

Property Item10 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 30 ];

Property Item11 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 31 ];

Property Item12 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 32 ];

Property Item13 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 33 ];

Property Item14 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 34 ];

Property Item15 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 35 ];

Property Item16 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 36 ];

Property Item17 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 37 ];

Property Item18 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 38 ];

Property Item19 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 39 ];

Property Item20 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 40 ];

Index TourDateAdm On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourAdmDR);

Index TourDate On DHCNurTourDate;

Index TourAdmUser On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourAdmDR, DHCNurTourUser);

Index TourUser On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourUser);

/// Creator:      lmm
/// CreatDate:    2019-04-19
/// Description:  分级巡视保存
/// Input：       parr:数据串(key|value^key|value),id:id,userId:用户ID
/// other:        w ##class(Nur.MNISV3.GradeTourRec).Save()
ClassMethod Save(parr As %String, id As %String, userId As %String, parrJson = "") As %String
{
    s tmp=""
    s a=##class(web.DHCMGNurComm).setmoudtmp(parr,.tmp)
    i (id=""){
        s rec=##class(Nur.MNISV3.GradeTourRec).%New()
    }else{
        s rec=##class(Nur.MNISV3.GradeTourRec).%OpenId(id)
    }
    q:'$d(tmp("DHCNurTourIfOut")) "err:"_"请填写是否离房!"
    q:tmp("DHCNurTourIfOut")="" "err:"_"请填写是否离房!"
    i '$d(tmp("DHCNurTourDate"))  d
    .s tmp("DHCNurTourDate")=+$h
    e  d
    .i tmp("DHCNurTourDate")["-" s tmp("DHCNurTourDate")=$zdh(tmp("DHCNurTourDate"),3)
    .i tmp("DHCNurTourDate")["/" s tmp("DHCNurTourDate")=$zdh(tmp("DHCNurTourDate"),1)  
    i '$d(tmp("DHCNurTourTime"))  d
    .s tmp("DHCNurTourTime")=$p($h,",",2)
    e  d
    .i tmp("DHCNurTourTime")[":" s tmp("DHCNurTourTime")=$zth(tmp("DHCNurTourTime"))
    //取当时患者的等级护理和床号
    i $d(tmp("DHCNurTourAdmDR")) d
    .s tmp("DHCNurTourPatBed")=##class(Nur.MNISV3.Service.PatientInfo).GetBedCode(tmp("DHCNurTourAdmDR"))
    .s tmp("DHCNurTourCareDesc")=##class(Nur.MNISV3.Service.PatientInfo).GetCareLevel(tmp("DHCNurTourAdmDR"))
    .s tmp("DHCNurTourCareDR")=##class(Nur.MNISV3.Service.PatientInfo).GetCareLevel(tmp("DHCNurTourAdmDR"))
    s tmp("DHCNurTourBarcodeType")="Reg"
    i $d(tmp("BarCode"))  d
    .i tmp("BarCode")["Bed" s tmp("DHCNurTourBarcodeType")="Bed"
    .e  i tmp("BarCode")["BED" s tmp("DHCNurTourBarcodeType")="Bed"
    .e  s tmp("DHCNurTourBarcodeType")="Reg"
    i $d(tmp("DHCNurTourDate")) s rec.DHCNurTourDate=tmp("DHCNurTourDate")
    i $d(tmp("DHCNurTourTime")) s rec.DHCNurTourTime=tmp("DHCNurTourTime")
    i $d(tmp("DHCNurTourAdmDR")) s rec.DHCNurTourAdmDR=tmp("DHCNurTourAdmDR")
    i $d(tmp("DHCNurTourCtlocDR")) s rec.DHCNurTourCtlocDR=tmp("DHCNurTourCtlocDR")
    i $d(tmp("DHCNurTourPatBed")) s rec.DHCNurTourPatBed=tmp("DHCNurTourPatBed")    
    i $d(tmp("DHCNurTourCareDR")) s rec.DHCNurTourCareDR=tmp("DHCNurTourCareDR")
    i $d(tmp("DHCNurTourCareDesc")) s rec.DHCNurTourCareDesc=tmp("DHCNurTourCareDesc")
    i $d(tmp("DHCNurTourIfOut")) s rec.DHCNurTourIfOut=tmp("DHCNurTourIfOut")
    i $d(tmp("DHCNurTourIfOutRes")) s rec.DHCNurTourIfOutRes=tmp("DHCNurTourIfOutRes")
    i $d(tmp("DHCNurTourSTAT")) s rec.DHCNurTourSTAT=tmp("DHCNurTourSTAT")
    i $d(tmp("DHCNurTourTunnelSTAT")) s rec.DHCNurTourTunnelSTAT=tmp("DHCNurTourTunnelSTAT")
    i $d(tmp("DHCNurTourTW")) s rec.DHCNurTourTW=tmp("DHCNurTourTW")
    i $d(tmp("DHCNurTourSkinSTAT")) s rec.DHCNurTourSkinSTAT=tmp("DHCNurTourSkinSTAT")
    i $d(tmp("DHCNurTourBarcodeType")) s rec.DHCNurTourBarcodeType=tmp("DHCNurTourBarcodeType")

    //处理 parrJson 对象
    //"{""5||11"":""jxjxjxjjx"",""5||10"":""hshshh"",""5||2"":""22"",""5||1"":""36.5"",""5||4"":""44"",""5||3"":""33"",""5||6"":""66"",""5||5"":""55"",""5||8"":""有"",""5||7"":""45"",""5||9"":""皮疹^寒战^胸闷""}
    i $g(parrJson)'="" {
        s itemType=""
        s set=##class(Nur.MNISV3.Common.JSON).Decode(parrJson)
        s key=set.Next("")
        while (key'="") {
            s value=set.GetAt(key)
            i key["||" { //分隔字符 第一个是类型
                s itemType=$p(key,"||",1)
                s itemIndex=$p(key,"||",2)
                s itm="Item"_itemIndex  
                if $g(value)'="" s $ZOBJPROPERTY(rec,itm)=value
            }
            s key=set.Next(key)
           
        }
        i itemType'="" s $ZOBJPROPERTY(rec,"ItemType")=itemType
    }
    
    s rec.DHCNurTourUser=userId
    s sc=rec.%Save()
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q rec.%Id()
}

/// Creator:      lmm
/// CreatDate:    2019-04-19
/// Description:  分级巡视删除
/// Input：       parr:数据串(key|value^key|value),id:id
/// other:        w ##class(Nur.MNISV3.GradeTourRec).Delete(1)
ClassMethod Delete(id As %String, userId As %String) As %String
{
    q:id="" "err:"_"id为空"
    s rec=##class(Nur.MNISV3.GradeTourRec).%OpenId(id)
    s rec.DHCNurTourCancelUser=userId
    s rec.DHCNurTourCancelDate=+$h
    s rec.DHCNurTourCancelTime=$p(+$h,",",2)
    s sc=rec.%Save()    
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q 0
}

Storage Default
{
<Data name="GradeTourRecDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>DHCNurTourDate</Value>
</Value>
<Value name="3">
<Value>DHCNurTourTime</Value>
</Value>
<Value name="4">
<Value>DHCNurTourAdmDR</Value>
</Value>
<Value name="5">
<Value>DHCNurTourCtlocDR</Value>
</Value>
<Value name="6">
<Value>DHCNurTourPatBed</Value>
</Value>
<Value name="7">
<Value>DHCNurTourCareDR</Value>
</Value>
<Value name="8">
<Value>DHCNurTourCareDesc</Value>
</Value>
<Value name="9">
<Value>DHCNurTourIfOut</Value>
</Value>
<Value name="10">
<Value>DHCNurTourIfOutRes</Value>
</Value>
<Value name="11">
<Value>DHCNurTourSTAT</Value>
</Value>
<Value name="12">
<Value>DHCNurTourTunnelSTAT</Value>
</Value>
<Value name="13">
<Value>DHCNurTourTW</Value>
</Value>
<Value name="14">
<Value>DHCNurTourSkinSTAT</Value>
</Value>
<Value name="15">
<Value>DHCNurTourUser</Value>
</Value>
<Value name="16">
<Value>DHCNurTourCancelUser</Value>
</Value>
<Value name="17">
<Value>DHCNurTourCancelDate</Value>
</Value>
<Value name="18">
<Value>DHCNurTourCancelTime</Value>
</Value>
<Value name="19">
<Value>DHCNurTourBarcodeType</Value>
</Value>
<Value name="20">
<Value>ItemType</Value>
</Value>
<Value name="21">
<Value>Item1</Value>
</Value>
<Value name="22">
<Value>Item2</Value>
</Value>
<Value name="23">
<Value>Item3</Value>
</Value>
<Value name="24">
<Value>Item4</Value>
</Value>
<Value name="25">
<Value>Item5</Value>
</Value>
<Value name="26">
<Value>Item6</Value>
</Value>
<Value name="27">
<Value>Item7</Value>
</Value>
<Value name="28">
<Value>Item8</Value>
</Value>
<Value name="29">
<Value>Item9</Value>
</Value>
<Value name="30">
<Value>Item10</Value>
</Value>
<Value name="31">
<Value>Item11</Value>
</Value>
<Value name="32">
<Value>Item12</Value>
</Value>
<Value name="33">
<Value>Item13</Value>
</Value>
<Value name="34">
<Value>Item14</Value>
</Value>
<Value name="35">
<Value>Item15</Value>
</Value>
<Value name="36">
<Value>Item16</Value>
</Value>
<Value name="37">
<Value>Item17</Value>
</Value>
<Value name="38">
<Value>Item18</Value>
</Value>
<Value name="39">
<Value>Item19</Value>
</Value>
<Value name="40">
<Value>Item20</Value>
</Value>
</Data>
<DataLocation>^Nur.MNISV3.GradeTourRecD</DataLocation>
<DefaultData>GradeTourRecDefaultData</DefaultData>
<ExtentSize>1</ExtentSize>
<IdLocation>^Nur.MNISV3.GradeTourRecD</IdLocation>
<IndexLocation>^Nur.MNISV3.GradeTourRecI</IndexLocation>
<Property name="%%CLASSNAME">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="%%ID">
<AverageFieldSize>3</AverageFieldSize>
<Selectivity>1</Selectivity>
</Property>
<Property name="DHCNurTourAdmDR">
<AverageFieldSize>6</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourBarcodeType">
<AverageFieldSize>5</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCancelDate">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCancelTime">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCancelUser">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCareDR">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCareDesc">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourCtlocDR">
<AverageFieldSize>3</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourDate">
<AverageFieldSize>5</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourIfOut">
<AverageFieldSize>4</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourIfOutRes">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourPatBed">
<AverageFieldSize>4</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourSTAT">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourSkinSTAT">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourTW">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourTime">
<AverageFieldSize>4</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourTunnelSTAT">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="DHCNurTourUser">
<AverageFieldSize>7</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item1">
<AverageFieldSize>12</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item10">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item11">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item12">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item13">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item14">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item15">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item2">
<AverageFieldSize>7</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item3">
<AverageFieldSize>4</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item4">
<AverageFieldSize>6</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item5">
<AverageFieldSize>10</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item6">
<AverageFieldSize>8</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item7">
<AverageFieldSize>6</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item8">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="Item9">
<AverageFieldSize>2</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<Property name="ItemType">
<AverageFieldSize>3</AverageFieldSize>
<Selectivity>100.0000%</Selectivity>
</Property>
<SQLMap name="IDKEY">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourAdmUser">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourDate">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourDateAdm">
<BlockCount>-4</BlockCount>
</SQLMap>
<SQLMap name="TourUser">
<BlockCount>-4</BlockCount>
</SQLMap>
<StreamLocation>^Nur.MNISV3.GradeTourRecS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}
